package com.lagou.homework_1_3;

//定义一个Worker类型
public class Worker {

    //私有属性
    String name;
    int age;
    double salary;

    //空构造
    public Worker() {
    }

    //有参构造
    public Worker(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    //get set方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void work() {
        System.out.println(getName() + "正在努力工作");
    }

    //to String 方法
    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }


    //为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Worker worker = (Worker) o;

        if (age == worker.age && name.equals(worker.name) && salary == worker.salary) {
            return true;
        }
        else {
            return false;
        }

    }

    //hashCode方法
    @Override
    public int hashCode() {
        int result;
        long temp;
        result = name.hashCode();
        result = 31 * result + age;
        temp = Double.doubleToLongBits(salary);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}
